<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script type="text/javascript" src="/js/jquery-1.11.0.min.js"></script>
    <script type="text/javascript" src="/js/jquery.validate.js"></script>
    <script type="text/javascript" src="/js/messages_zh.js"></script>

    <script type="text/javascript">
        function reg(type) {
            $.ajax({
                url:"/user/docheck.html",
                method:"post",
                data:"userName="+$("#userName").val(),

                success:function (data) {
                    $("#msg").html(data.msg);
                    if(data.status){
                        if(type==1){
                            $("#classForm").submit();
                        }
                    }
                }
            })
        }
    </script>

    <script type="text/javascript">



        $(function(){
            $("#classForm").validate({
                debug:true,  //调试模式，如果可以使用将不会跳转到指定页面
                rules:{
                    //字段的name属性：“校验器”
                    //字段的name属性：{“校验器”：“值”，“校验器”：“值”}
                    password:{
                        required:true,
                        digits:true,
                        rangelength:[3,18]	//长度区间
                    },
                    repassword:{
                        required:true,
                        equalTo:'#password'	//必须和某个值相同，与id为pwd相等
                    }
                },
                messages:{
                    password:{
                        required:"密码不能为空",
                        digits:"密码必须由数字组成",
                        rangelength:"密码由6-18位数字组成"
                    },
                    repassword:{
                        required:"确认密码不能为空",
                        equalTo:'确认密码和密码不一致'
                    }
                },
                submitHandler:function(form){
                    form.submit()
                }
            });

        });
    </script>

</head>
<body>

<form action="/user/docheck.html" method="post" id="classForm">
    <table border="1">
        <tr><td>用户名<input type="text" name="userName" onblur="reg(0)" id="userName"/><span id="msg" style="color: red"></span></td></tr><br/>
        <tr><td>密码<input type="password" name="password" id="password"></td></tr><br/>
        <tr><td>确认密码<input type="password" name="repassword" id="repassword"></td></tr><br/>
        <tr><td><input type="button" value="注册" onclick="reg(1)"><a href="/user/check.html">去登录</a></td></tr>
    </table>
</form>

</body>
</html>
